package cn.tedu.practice2303.LSS.day0408.HomeWork;

import java.io.*;

/**
 * 将当前目录下的所有文件都复制一份，复制的文件命名为:原
 * 文件名_cp.后缀
 * 比如原文件为:test.dat
 * 复制后的文件为:test_cp.dat
 */
public class Test01 {
    public static void main(String[] args) throws IOException {
        File dir = new File(".");
        if (dir.isDirectory()){
            File[] subs = dir.listFiles();
            for (File sub:subs) {
                String str =sub.getName();
                if (str.contains(".") && str.indexOf(".")!=0){
                    FileInputStream fis = new FileInputStream(str);
                    BufferedInputStream bis = new BufferedInputStream(fis);
                    str = str.replaceAll("\\.","_cp.");
                    FileOutputStream fos = new FileOutputStream(str);
                    BufferedOutputStream bos = new BufferedOutputStream(fos);
                    int d;
                    while((d= bis.read())!=-1) {
                    bos.write(d);
                    }
                    bis.close();
                    bos.flush();
                    bos.close();
                }
            }
            System.out.println("复制完成");
        }

    }
}
